from django.db import models
from django.core.cache import cache
# Create your models here.


class GameCategory(models.Model):
    name = models.CharField(max_length=100, verbose_name='分类名称')
    description = models.TextField(verbose_name='分类描述', null=True, blank=True)

    class Meta:
        db_table = 'game_category'
        verbose_name = '分类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Game(models.Model):
    name = models.CharField(max_length=100, verbose_name='游戏名称')
    category = models.ForeignKey(
        GameCategory,
        verbose_name='分类',
        related_name='games',
        on_delete=models.CASCADE
    )
    vendors = models.CharField(max_length=100, verbose_name='开发商')
    PLATFORM = (
        (1, 'PC'),
        (2, 'PS4'),
        (3, 'XBOX'),
    )
    platform = models.IntegerField(choices=PLATFORM, default=1, verbose_name='游戏平台')
    size = models.CharField(max_length=100, verbose_name='游戏大小')
    version = models.CharField(max_length=100, verbose_name='游戏版本')
    STATE = (
        (1, '上线'),
        (2, '下线'),
        (3, '维护中'),
    )
    state = models.IntegerField(choices=STATE, default=1, verbose_name='游戏状态')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='添加时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        db_table = 'game'
        verbose_name = '游戏'
        verbose_name_plural = verbose_name


    def __str__(self):
        return self.name

    # def save(self, *args, **kwargs):
    #     super().save(*args, **kwargs)
    #     cache.delete('game:list')
    #
    # def delete(self, *args, **kwargs):
    #     super().delete(*args, **kwargs)
    #     cache.delete('game:list')